﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMITDomain.Abstract;
using MMITDomain.Entities;

namespace MMITDomain.Concrete
{
    public class EFTransactionRoleRepository : ITransactionRoleRepository
    {
        EFDbContext dbContext = new EFDbContext();
        
        #region ITransactionRoleRepository Members

        public IQueryable<TransactionRole> TransactionRoles
        {
            get
            {
                return dbContext.TransactionRoles;
            }
        }

        public void SaveTransactionRole(TransactionRole objTransactionRole)
        {
            if (objTransactionRole.Id == 0)
            {
                dbContext.TransactionRoles.Add(objTransactionRole);
            }

            dbContext.SaveChanges();
        }

        public void DeleteTransactionRole(TransactionRole objTransactionRole)
        {
            dbContext.TransactionRoles.Remove(objTransactionRole);
        }

        public TransactionRole GetTransactionRoleById(int iTransactionRoleId)
        {
            return dbContext.TransactionRoles.Find(iTransactionRoleId);
        }

        public TransactionRole GetTransactionRoleByName(string strTransactionRole)
        {
            return dbContext.TransactionRoles.Where(o => o.Name == strTransactionRole)
                .SingleOrDefault<TransactionRole>();
        }

        #endregion
    }
}
